﻿using System;
using FlexiCommerce.Components;
using FlexiCommerce.Engine;

namespace FlexiCommerce.Collections
{
	/// <summary>
	/// Helps passing a delegate function used to determine wheter the item should be filtered.
	/// </summary>
	public class DelegateFilter : ItemFilter
	{
        readonly Function<PersistenceItem, bool> isPositiveMatch;

        public DelegateFilter(Function<PersistenceItem, bool> isPositiveMatch)
		{
			if (isPositiveMatch == null) throw new ArgumentNullException("isPositiveMatch");

			this.isPositiveMatch = isPositiveMatch;
		}

        public override bool Match(PersistenceItem item)
		{
			return isPositiveMatch(item);
		}
	}
}
